package com.zwx.aray.zigzag;


/**
 * 蜿蜒曲折
 *
 * @author 文希
 * @create 2019-06-27 0:20
 */
public class Solution {

    // todo 不成功
    public static String convert(String s,int numRows){
        int round = 2*numRows-2;
        if (s.length()==0 || numRows<=1){
            return s;
        }
        char[] chars = s.toCharArray();
        String result ="";
        for (int i = 0;i<numRows;i++){
            for (int j=i;j<chars.length;j++){
                result +=chars[j];
                if (i != 0 && i != numRows-1){
                    int zhongjian = j+round--;
                    if (zhongjian<chars.length){
                        result += chars[zhongjian];
                    }
                }

            }
        }
        return result;
    }

    public static void main(String[] args) {
        String s = "PAYPALISHIRING";
        String convert = convert(s, 7);
        System.out.println("convert = " + convert);
    }
}
